<?php

namespace App\Http\Controllers;

use App\Models\HouseBroker;
use App\Models\UserMessage;
use App\Models\WxUser;
use App\Tools\JsonTools;
use App\Tools\JwtTools;
use Illuminate\Http\Request;
use function Swoole\push;

class BrokerController extends Controller
{
    /**
     * @Notes:
     * @Author:Planc,
     * @Date: 2022/11/22,
     * @Time: 11:20,
     * 查询聊天列表
     */
    public function brokerMessage(Request $request){
        $brokerId=$request->id;
        $userMsg=UserMessage::Where('tid',$brokerId)->get()->toArray();
        $userId=[];
        foreach ($userMsg as $v){
            array_push($userId,$v['uid']);
        }
        $userId=array_unique($userId);
        $userInfo=WxUser::whereIn('id',$userId)->get(['id','user_image'])->toArray();
        $data=[
            'userInfo'=>$userInfo,
            'brokerId'=>$brokerId
        ];
        return JsonTools::JsonSuccess($data,200,'ok');
    }

    /**
     * @Notes:
     * @Author:Planc,
     * @Date: 2022/11/22,
     * @Time: 16:29,
     * 经纪人头像
     */
    public function brockerInfo(Request $request){
        $brokerId=$request->id;
        $uid=$request->post('uid');
        $brokerInfo=HouseBroker::where('id',$brokerId)->first()->toArray();
        $userInfo=WxUser::where('id',$uid)->first()->toArray();
        $data=[
            'brokerId'=>$brokerInfo['id'],
            'brokerImage'=>$brokerInfo['broker_image'],
            'userImage'=>$userInfo['user_image']
        ];
        return JsonTools::JsonSuccess($data,200,'ok');
    }
}
